package com.example.source_share.controller.user.account;

import com.example.source_share.service.user.account.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class RegisterController {
    @Autowired
    private RegisterService registerService;
    @PostMapping("/user/account/register")
    public Map<String,String> register(@RequestParam Map<String,String> map){
        String username=map.get("username");
        String encode_pass=map.get("password");
        String encode_confirmedPassword=map.get("confirmedPassword");
        StringBuilder password= new StringBuilder();
        StringBuilder confirmedPassword= new StringBuilder();
        System.out.println(encode_pass);
        //简单解密
        String str1 = "L73hz/sHgnKmQCD8YFfGj1toaR0S4JcTpi6rv5yw+BVbWPeNu2IlUOxEdqkM9XZ+A-*&^%$#@!";
        String str2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-/=!@#$%^&*";
        for (int i = 0; i < encode_pass.length(); i++) {
            int k = str1.indexOf(encode_pass.charAt(i));
            password.append(str2.charAt(k));
        }
        for (int i = 0; i < encode_pass.length(); i++) {
            int k = str1.indexOf(encode_confirmedPassword.charAt(i));
            confirmedPassword.append(str2.charAt(k));
        }

        System.out.println(password);
        return registerService.register(username,password.toString(),confirmedPassword.toString());

    }
}
